﻿using System;
using System.Linq;
using System.Activities;
using HybridLab.Workflow.Activities.Info;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Lab.Client;

namespace HybridLab.Workflow.Activities.CodeActivities
{
	[BuildActivity(HostEnvironmentOption.All)]
	public sealed class RepairLabEnvironmentActivity : CodeActivity
	{
		public InArgument<string> LabEnvironmentUri { get; set; }

		protected override void Execute(CodeActivityContext context)
		{
			var labUri = new Uri(context.GetValue(LabEnvironmentUri));
			var labService = context.GetExtension<TfsTeamProjectCollection>().GetService<LabService>();
			var lab = labService.GetLabEnvironment(labUri);
			
			context.LogMessage("Repairing environment {0}", lab.FullName);
			lab.Repair();
		}
	}
}
